package swing.project.standard;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import org.apache.log4j.Logger;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

/**
 * @Title: Jpanel2.java
 * @Description: TODO(添加描述)
 * @author H819
 * @date 2010-10-10
 * @version V1.0
 */
public class Jpanel6 extends JPanel implements ActionListener {
	private JLabel statuslable;
	private JButton buttonChoseFile;
	private static Logger log = Logger.getLogger(Jpanel6.class);
	private JLabel infolabel = new JLabel("");
	private final JCheckBox checkBox = new JCheckBox(
			ResourceBundle
					.getBundle("swing.project.standard.messages").getString("Jpanel6.maininfo.checkbox1")); //$NON-NLS-1$ //$NON-NLS-2$
	private final JCheckBox checkBox_1 = new JCheckBox(
			ResourceBundle
					.getBundle("swing.project.standard.messages").getString("Jpanel6.maininfo.checkbox2")); //$NON-NLS-1$ //$NON-NLS-2$
	private final JCheckBox checkBox_2 = new JCheckBox(
			ResourceBundle
					.getBundle("swing.project.standard.messages").getString("Jpanel6.maininfo.checkbox3")); //$NON-NLS-1$ //$NON-NLS-2$
	private final JCheckBox checkBox_3 = new JCheckBox(
			ResourceBundle
					.getBundle("swing.project.standard.messages").getString("Jpanel6.maininfo.checkbox4")); //$NON-NLS-1$ //$NON-NLS-2$
	private final JCheckBox checkBox_4 = new JCheckBox(
			ResourceBundle
					.getBundle("swing.project.standard.messages").getString("Jpanel6.maininfo.checkbox5")); //$NON-NLS-1$ //$NON-NLS-2$
	private final JRadioButton radioButton = new JRadioButton(
			ResourceBundle
					.getBundle("swing.project.standard.messages").getString("Jpanel6.radioButton.text")); //$NON-NLS-1$ //$NON-NLS-2$
	private final JRadioButton radioButton_1 = new JRadioButton(
			ResourceBundle
					.getBundle("swing.project.standard.messages").getString("Jpanel6.radioButton_1.text")); //$NON-NLS-1$ //$NON-NLS-2$
	private final JRadioButton radioButton_2 = new JRadioButton(
			ResourceBundle
					.getBundle("swing.project.standard.messages").getString("Jpanel6.radioButton_2.text")); //$NON-NLS-1$ //$NON-NLS-2$

	/**
	 * Create the panel.
	 */
	public Jpanel6() {

		setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.PREF_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.PREF_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.PREF_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.PREF_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.GLUE_COLSPEC, },
				new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.PARAGRAPH_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.PARAGRAPH_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.PARAGRAPH_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.PARAGRAPH_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.PARAGRAPH_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.PARAGRAPH_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.PARAGRAPH_GAP_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.PREF_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						RowSpec.decode("-11px:grow"), }));

		JLabel maininfo = new JLabel(
				ResourceBundle
						.getBundle("swing.project.standard.messages").getString("Jpanel6.maininfo.text")); //$NON-NLS-1$ //$NON-NLS-2$
		add(maininfo, "2, 4, 21, 1");
		checkBox.setSelected(true);

		add(checkBox, "2, 6, 21, 1");
		checkBox_1.setSelected(true);

		add(checkBox_1, "2, 8, 21, 1");
		checkBox_2.setSelected(true);

		add(checkBox_2, "2, 10, 21, 1");

		add(checkBox_3, "2, 12, 23, 1");

		add(checkBox_4, "2, 14, 23, 1");

		ButtonGroup group = new ButtonGroup();

		buttonChoseFile = new JButton(
				ResourceBundle
						.getBundle("swing.project.standard.messages").getString("Jpanel6.buttonChoseFile.text")); //$NON-NLS-1$ //$NON-NLS-2$
		buttonChoseFile.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				System.out.println("checkBox is selected :"
						+ checkBox.isSelected());
				System.out.println("checkBox_1 is selected :"
						+ checkBox_1.isSelected());
				System.out.println("checkBox_2 is selected :"
						+ checkBox_2.isSelected());
				System.out.println("checkBox_3 is selected :"
						+ checkBox_3.isSelected());
				System.out.println("checkBox_4 is selected :"
						+ checkBox_4.isSelected());
				
				
				

				// 首先判断数据库是否可以访问，再进行下一步。只要有一个不可用，则弹出提示框
				// if (!SystemServiceMonitor.isNetServiceOpen("129.9.200.235",
				// 1521)
				// || !SystemServiceMonitor.isFtpInServiceOpen(
				// "129.9.200.236", 21, "read", "readpdf")) {
				//
				// // 此处弹出对话框
				// JOptionPane.showMessageDialog(Jpanel6.this,
				// " oracle 数据库或 ftp 不可用");
				// return;
				//
				// }

				// Jpanel1.this.button.setEnabled(false);
			}
			// button.setEnabled(true);

		});

		add(radioButton, "4, 17, fill, center");
		radioButton.addActionListener(this);
		group.add(radioButton);

		add(radioButton_1, "6, 17, left, center");
		radioButton_1.addActionListener(this);
		group.add(radioButton_1);
		radioButton_2.setSelected(true);

		add(radioButton_2, "2, 17");
		radioButton_2.addActionListener(this);
		group.add(radioButton_2);

		add(buttonChoseFile, "8, 20, right, default");
	}

	/**
	 * Listens to the radio group.add(radioButton_2); buttons.
	 */
	public void actionPerformed(ActionEvent e) {

		AbstractButton aButton = (AbstractButton) e.getSource();
		System.out.println(aButton.getText());

		// System.out.println("radioButton is selsected :"+radioButton.isSelected());
		// System.out.println("radioButton_1 is selsected :"+radioButton_1.isSelected());
		// System.out.println("radioButton_2 is selsected :"+radioButton_2.isSelected());
		//

		if (radioButton_2.isSelected()) {//默认
			checkBox.setSelected(true);
			checkBox_1.setSelected(true);
			checkBox_2.setSelected(true);
			checkBox_3.setSelected(false);
			checkBox_4.setSelected(false);

		} else if (radioButton.isSelected()) {//全选
			checkBox.setSelected(true);
			checkBox_1.setSelected(true);
			checkBox_2.setSelected(true);
			checkBox_3.setSelected(true);
			checkBox_4.setSelected(true);

		} else if (radioButton_1.isSelected()) {//全不选
			checkBox.setSelected(false);
			checkBox_1.setSelected(false);
			checkBox_2.setSelected(false);
			checkBox_3.setSelected(false);
			checkBox_4.setSelected(false);
		} else {

		}

	}
}